# -*- coding: utf-8 -*-
'''
Created on 2013-6-1
容器类
@author: 不懂d叛逆
'''
import ccjhMan, ccjhObj
class ccjhContainer(ccjhObj.ccjhObj):

	def __init__(self):
		self.items = {}
		self.LongID = 0
		return

	def ClearItem(self):
		self.items.clear()
		return

	def AddItem(self, obj):
		if isinstance(obj, ccjhMan.ccjhMan):
			if obj.LongID > 0:
				if obj.LongID in self.items:
					self.items[obj.LongID].setTo(obj)
					# self.debugShowItem()
				else:
					self.items[obj.LongID] = obj
		return

	def RemoveItem(self, obj):
		if isinstance(obj, int):
			del(self.items[obj])
		# self.debugShowItem()

	def Find(self, nID):
		if isinstance(nID, int) and nID in self.items:
			return self.items[nID]
		return 0

	def Contains(self, obj):
		return obj.LongID in self.items

	def debugShowItem(self):
		for (k, v) in self.items.items():
			print("场景", k, v.ToString())
		return

	def FindByID(self, idString):
		for v in self.items.values():
			if v.get("I") == idString:
				return v
		return 0
